package com.shp.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 数据验证类
 * @author ZWL
 * @Version: 1.0
 * @create: 2020/2/26 21:17
 */
public class ValidateUtils {

    /**
     * 验证邮箱
      * @param email 邮箱
     * @return 是邮箱返回true；否则返回false
     */
    public static boolean checkEmail(String email){
        boolean flag = false;
        try {
            String regex = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(email);
            flag = matcher.matches();
        }catch (Exception e){
            return false;
        }
        return flag;
    }

    /**
     * 验证手机号码
     * @param mobileNumber 手机号码
     * @return 是手机号码返回true；否则返回false
     */
    public static boolean checkMobileNumber(String mobileNumber){
        boolean flag = false;
        try{
            String regex = "^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(mobileNumber);
            flag = matcher.matches();
        }catch (Exception e){
            return false;
        }
        return flag;
    }
}
